﻿using System;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("api/[Action]")]
public class VerifyCodeController : Controller
{
    /// <summary>
    /// 生成图片验证码
    /// </summary>
    /// <param name="codeType">验证码类型 0：纯数字 1：数字+字母 2：数字运算 默认1</param>
    /// <returns></returns>
    [HttpPost(Name="verify")]
    public VerifyCodeResult verify()
    {
        string codeType = "0";
        string uuid = Guid.NewGuid().ToString().Replace("-", "");
        var codeInfo = new VerifyCode();
        if (codeType == "1")
        {
            codeInfo = VerifyUtils.CreateVerifyCode(4, VerifyUtils.VerifyCodeType.CHAR);
        }
        else if (codeType == "2")
        {
            codeInfo = VerifyUtils.CreateVerifyCode(4, VerifyUtils.VerifyCodeType.ARITH);
        }
        else if (codeType == "0")
        {
            codeInfo = VerifyUtils.CreateVerifyCode(4, VerifyUtils.VerifyCodeType.NUM);
        }
        var obj = new { uuid, img = codeInfo.Base64Str };
        return new VerifyCodeResult(codeInfo.Code, obj.img);
    }
}